<template>
    <div class="home-page">
        <section class="py-5 text-center container">
            <div class="row py-lg-5">
                <div class="col-lg-6 col-md-8 mx-auto">
                    <img src="../assets/patterns.e8579768.png" alt="" class="w-50">
                    <h2 class="font-weight-light">随心写作，自由表达</h2>
                    <a href="#" class="btn btn-primary my-2">开始写文章</a>
                </div>
            </div>
        </section>
        <h4 class="font-weight-bold text-center">发现精彩</h4>
        <column-list :list="list"></column-list>
    </div>
</template>

<script lang="ts">
import { computed, defineComponent, onMounted } from 'vue'
import { useStore } from 'vuex';
import { GlobalDataProps } from '@/store';
import ColumnList from './ColumnList.vue';

export default defineComponent({
    name: 'HomeIndex',
    components: {
        ColumnList,
        // UploaderFile
    },
    setup() {
        const store = useStore<GlobalDataProps>()
        // 组件挂载的时候调用
        onMounted(() => {
            store.dispatch('fetchColumns')
        })
        const list = computed(() => store.getters.getColumns)
        // const beforeUpload = (file: File) => {
        //     const isJPG = file.type === 'image/jpeg'
        //     // 自定义逻辑
        //     if(!isJPG) {
        //         createMessage('上传图片只能是 JPG 格式', 'error')
        //     }
        //     return isJPG
        // }
        // const onFileUploaded = (rawData: PesponseType<ImageProps>) => {
        //     createMessage(`上传图片ID${rawData.data._id}`, 'success')
        // }
        const biggerColumnsLenss = computed(() => store.getters.biggerColumnsLen)
        return {
            list: list,
            biggerColumnsLenss
            // beforeUpload,
            // onFileUploaded
        }
    },
})
</script>
